import React, {Suspense, lazy} from 'react'

const LazyComp = lazy(() => import('./Lazy'))


let data = ''
let promise = ''

function requestData() {
    if (data) return data
    if (promise) throw promise
    promise = new Promise(resolve => {
        setTimeout(() => {
            data = 'data resolved'
            resolve()
        }, 2000)
    })
    throw promise
}

function SuspenseComp() {
    const data = requestData()
    return <div>{data}</div>
}

export default () => (
    <Suspense fallback={'loading data'}>
        <SuspenseComp/>
        <LazyComp/>
    </Suspense>
)


